﻿// ==================================================
// Copyright © 2016 杭州伯庸科技 版权所有
//
// 文 件 名：SchemaCompare
// 功能描述：
//
// 创建标识：Yu.Liang(俞 亮) 2018/3/19 16:53:57
//
// 修改标识：
// 修改描述：
// ==================================================

using System.Drawing;
using System.Reflection;
using System.Windows.Forms;
using Shine.Framework;
using SuperMap.Realspace;
using SuperMap.Data;

namespace Shine.SchemaManager
{
    internal class SchemaCompare : BaseCommand
    {
        IApplication m_Application = null;

        public SchemaCompare()
        {
            base.m_caption = "方案对比";
            base.m_name = "SchemaCompare";
            base.m_toolTip = "方案对比";
            base.m_message = "方案对比";
            base.m_category = "schema";
        }

        public override void OnCreate(object hook)
        {
            m_Application = hook as IApplication;
            (m_Application as IFramework).SceneControl.MouseUp += SceneControl_MouseUp;
            (m_Application as IFramework).SceneControl2.MouseUp += SceneControl2_MouseUp;

            (m_Application as IFramework).SceneControl2.Parent.SizeChanged += Parent_SizeChanged;
        }

        private void Parent_SizeChanged(object sender, System.EventArgs e)
        {
            if ((m_Application as IFramework).IsSceneCompare)
            {
                (m_Application as IFramework).SceneControl2.Width = (m_Application as IFramework).SceneControl.Parent.Width / 2;
                (m_Application as IFramework).SceneControl.Width = (m_Application as IFramework).SceneControl.Parent.Width / 2;
            }
        }

        private void SceneControl_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle)
            {
                if ((m_Application as IFramework).IsSceneCompare)
                {
                    SuperMap.Realspace.Camera c = (m_Application as IFramework).SceneControl.Scene.Camera;
                    (m_Application as IFramework).SceneControl2.Scene.Camera = c;
                    (m_Application as IFramework).SceneControl2.Scene.Refresh();
                }

            }
        }

        private void SceneControl2_MouseUp(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle)
            {
                if ((m_Application as IFramework).IsSceneCompare)
                {
                    // (m_Application as IFramework).SceneControl.Map.Center = new SuperMap.Data.Point2D((m_Application as IFramework).SceneControl.Scene.Camera.Longitude, (m_Application as IFramework).SceneControl.Scene.Camera.Latitude);
                    // (m_Application as IFramework).MapControl.Map.Refresh();

                    SuperMap.Realspace.Camera c = (m_Application as IFramework).SceneControl2.Scene.Camera;
                    (m_Application as IFramework).SceneControl.Scene.Camera = c;
                    (m_Application as IFramework).SceneControl.Scene.Refresh();
                }

            }
        }

        public override void OnClick()
        {
            if ((m_Application as IFramework).IsSceneCompare == false)
            {
                (m_Application as IFramework).SceneControl.Dock = DockStyle.Left;
                (m_Application as IFramework).SceneControl2.Dock = DockStyle.Right;

                (m_Application as IFramework).SceneControl2.Visible = true;
                (m_Application as IFramework).SceneControl.Width = (m_Application as IFramework).SceneControl.Parent.Width / 2;
                (m_Application as IFramework).SceneControl2.Width = (m_Application as IFramework).MapControl.Parent.Width / 2;
                (m_Application as IFramework).SceneControl2.Scene.Camera = (m_Application as IFramework).SceneControl.Scene.Camera;
                (m_Application as IFramework).MapControl.Visible = false;

                (m_Application as IFramework).IsSceneCompare = true;
                (m_Application as IFramework).IsMutualMap = false;
            }
            else
            {
                (m_Application as IFramework).SceneControl.Dock = DockStyle.Fill;
                (m_Application as IFramework).SceneControl2.Dock = DockStyle.Right;
                (m_Application as IFramework).SceneControl2.Visible = false;

                (m_Application as IFramework).IsSceneCompare = false;
            }
        }

        public override int Bitmap
        {
            get
            {
                string imgFile = Application.StartupPath + "\\Images\\" + GetType().Name + ".png";

                if (System.IO.File.Exists(imgFile) == false) return 0;

                return new Bitmap(Image.FromFile(imgFile)).GetHbitmap().ToInt32();
            }
        }

        public override bool Enabled
        {
            get { 
                //return (m_Application as IFramework).IsMapCtrlactive; 
                return false;
            }
        }
    }
}
